package
{
	import flash.display.Graphics;
	import flash.display.Sprite;
	
	/**
	 * A ball  
	 * @author PC-100
	 * 
	 */	
	public class Ball extends Sprite implements IUpdater
	{
		private var vx:Number = 5;
		private var vy:Number = 5;
		
		public var radius:Number = 20;
		
		public function Ball()
		{
			super();
			
			drawBall();
		}
		/**
		 * 
		 * 
		 */		
		private function drawBall():void
		{
			var g:Graphics = this.graphics;
			g.beginFill( 0xff0000 );
			g.drawCircle(0,0,radius);
			g.endFill();
		}
		/**
		 *  update
		 * 
		 */		
		public function update():void
		{
			// 更新坐标
			x += vx;
			y += vy;
			// 边界检测，反向
			if( x < radius )
			{
				x = radius;
				reverseLR();
			}else if( x > stage.stageWidth - radius )
			{
				x = stage.stageWidth - radius;
				reverseLR();
			}
			
			if( y < radius )
			{
				y = radius;
				reverseTB();
			}else if( y > stage.stageHeight - radius )
			{
				y = stage.stageHeight - radius;
				reverseTB();
			}
				
			
		}
		/**
		 * 垂直反向 
		 * 
		 */		
		public function reverseTB():void
		{
			vy *= -1;
		}
		/**
		 * 水平反向 
		 * 
		 */		
		public function reverseLR():void
		{
			vx *= -1;
		}
		
		public function updateSpeed(_vx:Number, _vy:Number):void
		{
			vx = _vx;
			vy = _vy;
		}
	}
}